﻿using System.Globalization;
using System.Runtime.CompilerServices;

namespace CodingExercises._1_25;

public class TryExtractDateComponents
{
    //解析日期并提取其组成部分
    public static bool Method(
        string dateInput,
        out int year,
        out int month,
        out int day)
    {
        if (DateTime.TryParse(
                dateInput,
                result: out DateTime parsedDate))
        {
            year = parsedDate.Year;
            month = parsedDate.Month;
            day = parsedDate.Day;
            return true;
        }
        else
        {
            year = 0;
            month = 0;
            day = 0;
            return false;
        }
    }
}